package xuecheng.tool.json;

import xuecheng.tool.json.impl.JsonUtilsFastJsonImpl;
import xuecheng.tool.json.impl.JsonUtilsGsonImpl;

/**
 * json 工具类创建工厂
 *
 * @author PengXueCheng
 * @version 1.0.0
 */
public class JsonUtilsFactory {

    private static final JsonUtils FAST_JSON;
    private static final JsonUtils GSON;

    static {
        FAST_JSON = JsonUtilsFastJsonImpl.getInstance();
        GSON = JsonUtilsGsonImpl.getInstance();
    }

    /**
     * 获取一个 json 工具
     *
     * @param type
     *            类型枚举
     * @return
     */
    public static JsonUtils obtain(JsonTypeEnum type) {
        JsonUtils jsonUtils = null;
        switch (type) {
            case GSON:
                jsonUtils = GSON;
                break;
            case FAST_JSON:
                jsonUtils = FAST_JSON;
                break;
            default:
                break;
        }
        return jsonUtils;
    }

    /**
     * 获取一个 json 工具
     *
     * @return
     */
    public static JsonUtils obtain() {
        return obtain(JsonTypeEnum.GSON);
    }

}
